import React from 'react';
import { inject, observer} from 'mobx-react';
import {Spin,Table,Button,Modal,Row, Col,message,Tooltip} from 'antd';
import { WeaNewScroll,WeaLeftRightLayout,WeaHelpfulTip,WeaInputNumber,WeaLocaleProvider,WeaCheckbox,WeaTools,WeaTop,WeaSearchGroup,WeaFormItem,WeaBrowser,WeaRightMenu} from 'ecCom';
import * as Util from '../../util/Util'
const getLabel = WeaLocaleProvider.getLabel;
const toJS = mobx.toJS;
@inject('taskBaseStore')
@observer
export default class TaskBase extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        menu :[
        {
          key: '0',
          icon: <i className='icon-coms-Save-as' />,
          content: '保存',
          onClick: key => this.saveBase(),
        }
        ],
        _height:Util.getCurrentHeight(),
      }
    }
    componentWillMount() {//一些初始化请求
      const{taskBaseStore} = this.props;
      taskBaseStore.getTaskBase({});
    }
    onItemChange(v,typeid){
      const{taskBaseStore} = this.props;
      taskBaseStore[typeid] = v;
    }
    saveBase(){
      const{taskBaseStore} = this.props;
      taskBaseStore.saveTaskBase({doback:function(status){
        if(status==1){
          message.success('保存成功');
        }else{
          message.error("保存失败");
        }
      }});
    }
    render() {
      const{menu,_height} = this.state;
      const{taskBaseStore} = this.props;
      const{loading,isdel,fbdeltime,docArray,canedit,isshow} = taskBaseStore;
      return (
        <div className="wea-workrelate-task-base" style={{height:_height}}>
        {isshow && <WeaRightMenu datas={canedit?menu:[]} showUrlItem={false} style={{height:'100%'}}>
            <WeaTop
              title={getLabel(382505,"任务模块基础设置")}
              icon={<i className='icon-coms-ModelingEngine-o' />}
              iconBgcolor='rgb(150, 53, 138)'
              buttons = {canedit ? [(<Tooltip title="保存设置"><Button type='primary' onClick={()=> this.saveBase()}>保存</Button></Tooltip>)]:[]}
              showDropIcon={true}
              dropMenuDatas = {canedit?menu:[]}/>
                <Spin spinning={loading}>
                  <WeaNewScroll height={_height-80}>
                    <WeaSearchGroup title='基本信息' showGroup={true} col={2}>
                          <div style={{margin:"5px 20px 0"}}>
                            <Row gutter="2">
                                <Col span={4}>附件上传目录</Col>
                                <Col span={7}><WeaBrowser  type={"doccategory"} viewAttr={canedit?"2":"1"} replaceDatas={toJS(docArray)} onChange={(ids, names, datas) => this.onItemChange(datas,"docArray")}/></Col>
                                <Col span={2}></Col>
                                <Col span={4}>责任人是否可删除任务</Col>
                                <Col span={7}><WeaCheckbox style={{marginRight:"10px"}} value={isdel} display="switch" viewAttr={canedit?"2":"1"} onChange={(v)=>this.onItemChange(v,"isdel")}/><WeaHelpfulTip title="创建人不是自己，责任人是自己的任务是否有删除权限" placement="bottomLeft"/></Col>
                            </Row>
                            <Row gutter="2" style={{marginTop:'10px'}}>
                                <Col span={4}>反馈信息可删除时间(分钟)</Col>
                                <Col span={7}><WeaInputNumber value = {fbdeltime} min={0}  viewAttr={canedit?"2":"1"} onChange = {(v)=>this.onItemChange(v,"fbdeltime")}/></Col>
                            </Row>
                        </div>
                    </WeaSearchGroup>
                  </WeaNewScroll>
                </Spin>
          </WeaRightMenu>}
      </div>
    )
  }
};